Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
broccoli-caching-writer
Advanced tools
Broccoli plugin that allows simple caching (while still allowing N:N) based on the input tree hash.
The broccoli-caching-writer package is a Broccoli plugin that provides a base class for Broccoli plugins that need to cache their output. It helps in optimizing build times by caching the results of expensive operations and reusing them when the input hasn't changed.
Caching Output
This feature allows you to create a custom Broccoli plugin that caches its output. The `updateCache` method is where you perform your expensive operations, and the results are cached for future builds.
const CachingWriter = require('broccoli-caching-writer');
const fs = require('fs');
class MyCachingWriter extends CachingWriter {
updateCache(srcDir, destDir) {
// Perform expensive operations here
fs.writeFileSync(`${destDir}/output.txt`, 'Cached content');
}
}
module.exports = MyCachingWriter;
Handling Multiple Input Nodes
This feature allows you to handle multiple input nodes. The `updateCache` method receives an array of source directories, enabling you to process multiple inputs and cache their results.
const CachingWriter = require('broccoli-caching-writer');
const fs = require('fs');
class MultiInputCachingWriter extends CachingWriter {
constructor(inputNodes, options) {
super(inputNodes, options);
}
updateCache(srcDirs, destDir) {
// srcDirs is an array of input directories
srcDirs.forEach((srcDir, index) => {
fs.writeFileSync(`${destDir}/output${index}.txt`, `Cached content from ${srcDir}`);
});
}
}
module.exports = MultiInputCachingWriter;
Custom Cache Key
This feature allows you to define a custom cache key for your plugin. The `cacheKey` method generates a unique key that can be used to determine if the cache should be invalidated.
const CachingWriter = require('broccoli-caching-writer');
const fs = require('fs');
const crypto = require('crypto');
class CustomCacheKeyWriter extends CachingWriter {
constructor(inputNodes, options) {
super(inputNodes, options);
}
cacheKey() {
// Generate a custom cache key
return crypto.createHash('md5').update('custom-key').digest('hex');
}
updateCache(srcDir, destDir) {
fs.writeFileSync(`${destDir}/output.txt`, 'Cached content with custom key');
}
}
module.exports = CustomCacheKeyWriter;
The broccoli-plugin package provides a base class for Broccoli plugins, similar to broccoli-caching-writer but without built-in caching functionality. It is more general-purpose and can be extended to create various types of Broccoli plugins.
The broccoli-persistent-filter package is another Broccoli plugin base class that provides persistent caching. It is designed for plugins that need to filter files and cache the results, similar to broccoli-caching-writer but with a focus on filtering operations.
The broccoli-funnel package is used to funnel files from one Broccoli tree to another. While it doesn't provide caching, it is often used in conjunction with caching plugins to optimize build processes by selecting specific files or directories.
Drop-in-replacement for
broccoli-writer adding a thin
caching layer based on the computed hash of the input directory trees. If any
file in an input node has changed, the build
method will be called,
otherwise (if input is the same) the results of the last build
call will be
used instead.
var Plugin = require('broccoli-caching-writer');
MyPlugin.prototype = Object.create(Plugin.prototype);
MyPlugin.prototype.constructor = MyPlugin;
function MyPlugin(inputNodes, options) {
options = options || {};
// options.inputFiles === array of globs, to consider for the cache key
Plugin.call(this, inputNodes, {
annotation: options.annotation
});
}
MyPlugin.prototype.build = function() {
// cache has been busted
// do anything, for example:
// 1. read from this.inputPaths
// 2. do something based on the result
// 3. and then, write to this.outputPath
};
new CachingWriter(inputNodes, options)
Call this base class constructor from your subclass constructor.
inputNodes
: An array of input nodes.
options
:
name
, annotation
, persistentOutput
: Same as
broccoli-plugin;
see there.
cacheInclude
(default: []
): An array of regular expressions that files and directories in an input node must pass (match at least one pattern) in order to be included in the cache hash for rebuilds. In other words, a whitelist of patterns that identify which files and/or directories can trigger a rebuild.
cacheExclude
(default: []
): An array of regular expressions that files and directories in an input node cannot pass in order to be included in the cache hash for rebuilds. In other words, a blacklist of patterns that identify which files and/or directories will never trigger a rebuild.
Note, in the case when a file or directory matches both an include and exlude pattern, the exclude pattern wins
plugin.listFiles
list files matched, helpful as it allows us avoid a second glob, lexicographically sorted by relativePath.
plugin.listEntries
list entries (stat objects) of files matched, helpful when further FS information is required on rebuild, lexicographically sorted by relativePath.
I know, right?
Running the tests:
npm install
npm test
This project is distributed under the MIT license.
FAQs
Broccoli plugin that allows simple caching (while still allowing N:N) based on the input tree hash.
We found that broccoli-caching-writer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.